<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <input type="hidden" id="id" name="id">
            <input type="hidden" id="userid" name="userid">

            <div class='form-group'>
                <label class='col-md-2 control-label'>用户名</label>
                <div class='col-md-10'>
                    <input class='form-control' placeholder='username' type='text' name='username' id='username'
                           data-bv-notempty='true' data-bv-notempty-message='username 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-2 control-label'>用户昵称</label>
                <div class='col-md-10'>
                    <input class='form-control' placeholder='nickname' type='text' name='nickname' id='nickname'
                           data-bv-notempty='true' data-bv-notempty-message='nickname 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-2 control-label'>手机号</label>
                <div class='col-md-10'>
                    <input class='form-control' placeholder='phone' type='text' name='phone' id='phone'
                           data-bv-notempty='true' data-bv-notempty-message='phone 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-2 control-label'>用户状态</label>
                <div class='col-md-10'>

                    <select name="status" class="form-control input-sm" id="status">

                    </select>
                </div>
            </div>


            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='mfflUserList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
    });

    initData();

    function initData() {
        var userid = getUrlParam("userid");
        if (userid != "") {
            $.ajax({
                type: 'get',
                url: '/mfflUsers/' + userid,
                async: false,
                success: function (data) {
                    $('#id').val(data.id);
                    $('#userid').val(data.userid);
                    $('#username').val(data.username);
                    $('#nickname').val(data.nickname);
                    $('#phone').val(data.phone);
                    $('#status').val(data.status);
                    var str = '';
                    str += '<option value="1" '+(data.status=='1'?'selected':'')+' >正常</option>';
                    str += '<option value="2" '+(data.status=='2'?'selected':'')+' >锁定</option>';
                    $('#status').html(str);

                }
            });
        }
    }

    function update() {
        $('#form').bootstrapValidator();
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        var formdata = $("#form").serializeObject();

        $.ajax({
            type: 'put',
            url: '/mfflUsers',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {

                if (data.errCode == "200"){
                    layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                        location.href = "mfflUserList.html";
                    });
                }else {
                    layer.msg("修改失败");
                }


            }
        });
    }

</script>
</body>
</html>
